<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>

<script type="text/javascript">
	 	dojo.require("dijit.Editor");
		dojo.require("dijit.form.ValidationTextBox");
		dojo.require("dojox.validate.regexp");
		dojo.require("dojo.parser");
	</script>

<script type="text/javascript">
		$(document).ready(function() {
			$("input[name='btnCancle']").click(function() {
				var uri = ISS.lang.getBasePath()+'index.php/channel/channel';
				window.location = uri;
			});
		}); 
	</script>

<?php
echo html::Stylesheet(
array
(
				'media/css/channel_block.css',
),
array
(
				'screen',
)
);
?>

<div id="geneContainer"><?php print form::open_multipart('channel/channel/save');?>

<div id="channelBlock">
<div id="channelBlockTop">
<h3><?php echo ($mode=='add') ? 'เพิ่มสถานีเพลง' : 'แก้ไขสถานีเพลง'; ?></h3>
<?php
$array = array('mode' => $mode);
print form::hidden($array);
if ($mode=='edit') {
	$array = array('id' => $form['id']);
	print form::hidden($array);
}
?>
<p><?php echo (empty($status) ? 'กรุณาระบุข้อมูลให้ครบถ้วน' : html::specialchars($status)); ?></p>
</div>
<div id="channelBlockBody">
<table>
	<tr>
		<td>ชื่อ::</td>
		<td><input id="txtName" type="text" name="txtName"
			value="<?php echo html::specialchars($form['title']); ?>"
			style="width: 100px;" dojoType="dijit.form.ValidationTextBox"
			trim="true" required="true" invalidMessage="กรุณาระบุชื่อสถานีเพลง" />
		<div id='errName' class='channelBlockError'><?php echo (empty ($errors['txtName'])) ? '' : $errors['txtName']; ?>
		</div>
		</td>
	</tr>
	<tr>
		<td>คำอธิบาย::</td>
		<td><textarea dojoType="dijit.Editor" id="txtDescription"
			name="txtDescription">
			<?php echo html::specialchars($form['description']); ?>
							  	</textarea>
		<div id='errDescription' class='geneBlockError'><?php echo (empty ($errors['txtDescription'])) ? '' : $errors['txtDescription']; ?>
		</div>
		</td>
	</tr>
	<tr>
		<td>รูปภาพ::</td>
		<td><?php
		//		Kohana::log("debug","show logo" );
		if (!empty($form['channel_picture'])) {
			//			Kohana::log("debug",url::base() . html::specialchars($form['channel_picture']) );
			echo '<img id=imgLogo  alt="'. html::specialchars($form['title']) .'" src="'. url::base() . html::specialchars($form['channel_picture']) .'" />';
			echo '<br/>';
		}
		$attributes = array('name' => 'txtLogo');
		echo form::upload($attributes, '');
		?>
		<div id='errLogo' class='channelBlockError'><?php echo (empty ($errors['txtLogo'])) ? '' : $errors['txtLogo']; ?>
		</div>
		</td>
	</tr>
	<tr>
		<td>รายการเพลง:</td>
		<td>
		<?php 
		//show selected playlist in channel
		if (!empty($playlists)) {
			foreach ($playlists as $row) {
				if (!empty($row['owner'])) {
					Kohana::log("debug"," checked ".$row['owner']);
					if ($row['owner']==1){
							echo '<input type="checkbox" name="chbPl[]" value=" '.$row['id'].' " checked="checked" >'.$row['title'].'<br/>';
						}else{
							echo '<input type="checkbox" name="chbPl[]" value=" '.$row['id'].' ">'.$row['title'].'<br/>';
						}
				}else{
					echo '<input type="checkbox" name="chbPl[]" value=" '.$row['id'].' ">'.$row['title'].'<br/>';
				}
			}
		}
		?>
		</td>
	</tr>
</table>
</div>
</div>
<div id="channelBlockBot"><?php 
print form::submit('btnSave', 'บันทึก');
?> <input type="button" id="btnCancle" name="btnCancle" value="ยกเลิก" />
</div>
<?php print form::close(); ?></div>